//ship.java

public class Ship extends SpaceOb {
	private boolean isThrusting;
	private boolean clockwise;
	private boolean counterClockwise;
	final private double length=50;
	final private double width=50;
	final private double turnRate=1;
	final private double accelRate=1;
	final private double decelRate=1;
	//final private double maxSpeed;
	
	//Constructor
	public Ship() {
		super(true);
		isThrusting = false;
		clockwise = false;
		counterClockwise = false;
	}
	
	//Staðsetning efri hornpunkts
	public double getPosition1x() {
		double tempX = getPosx();
		double tempAngle = getFaceAngle();
		return tempX-Math.cos(tempAngle)*length-Math.sin(tempAngle)*width;
	}
	
	//Staðsetning neðri hornpunkts
	public double getPosition2x() {
		double tempX = getPosx();
		double tempAngle = getFaceAngle();
		return tempX-Math.cos(tempAngle)*length+Math.sin(tempAngle)*width;
	}
	
	//Staðsetning efri hornpunkts
	public double getPosition1y() {
		double tempY = getPosy();
		double tempAngle = getFaceAngle();
		return tempY-Math.sin(tempAngle)*length+Math.cos(tempAngle)*width;
	}
	
	//Staðsetning neðri hornpunkts
	public double getPosition2y() {
		double tempY = getPosy();
		double tempAngle = getFaceAngle();
		return tempY-Math.sin(tempAngle)*length-Math.cos(tempAngle)*width;
	}
	
	//Athuga: Frampunktur skipsins er fengin með getposx/y úr spaceobj clasa.
	
	
	public boolean getThrusting() {
		return isThrusting;
	}
	
	public void setThrusting(boolean meh) {
		isThrusting = meh;
	}
	
	public boolean getCounterClockwise() {
		return counterClockwise;
	}
	
	public void setCounterClockwise(boolean monet) {
		counterClockwise = monet;
	}
	public boolean getClockwise() {
		return counterClockwise;
	}
	
	public void setClockwise(boolean blah) {
		clockwise = blah;
	}
	
	
	/*
	Eftirfarandi aðferð:
	- Update-ar faceangle dependant á clockwise og counterclockwise
	- Update-ar hraða based á hvort það sé að thrust-a
	- Update-ar stöðuna based á hraðanum
	*/
	
	public void update() {
		if(counterClockwise) {
			incFaceAngle(turnRate);
		}
	
		if(clockwise) {
			incFaceAngle(-turnRate);
		}
	
		if(isThrusting) {
			incVelx(accelRate*Math.cos(getFaceAngle()));
			incVely(accelRate*Math.sin(getFaceAngle()));
		}	
		
		//Deceletarion
		incVelx(decelRate*getVelx());
		incVely(decelRate*getVely());
	
		// else if(getVelx!=0 || getVely!=0) {	
			// incVelx(decelRate*Math.cos(getFaceAngle())
			// incVely(decelRate*Math.sin(getFaceAngle())
		// }
	
		incPosx(getVelx());
		incPosy(getVely());
		if(getPosx()>1000){incPosx(-2000);}
		if(getPosx()<-1000){incPosx(2000);}
		incPosy(getVely());
		if(getPosy()>1000){incPosy(-2000);}
		if(getPosy()<-1000){incPosy(2000);}
	}
	
	//Teiknar skipið, Athuga að ef einhver hornpunktur fer útaf þá teleportast skipið.
	public void draw() {
		double[] fokju = {getPosx(), getPosition1x(), getPosition2x()};
		double[] fknhell = {getPosy(), getPosition1y(), getPosition2y()};
		StdDraw.filledPolygon(fokju,fknhell);
		//Geyma þangað til við vitum hvernig á að gera continuous hluti og e-ð.
		
	}
	
}